package com.working.libbase.storage

import android.content.Context
import android.content.SharedPreferences
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.preferencesKey
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.createDataStore
import com.tencent.mmkv.MMKV
import com.working.libbase.model.BackUpModel
import com.working.libcommon.helper.AndroidHelper

object Storage {

    //*******************use SharedPreferences


    private val storage: SharedPreferences by lazy {
        AndroidHelper.application.getSharedPreferences("wan_android", Context.MODE_PRIVATE)
    }

    var backUpList by storage.autoPref<MutableList<BackUpModel>>(arrayListOf())

    var isBlackMode by storage.autoPref(false)

    var numberOfStartUp by storage.autoPref(0)
    //*******************use SharedPreferences


    //*******************use DataStore
    private const val PREFERENCE_NAME = "DataStore"
    val dataStore: DataStore<Preferences> = AndroidHelper.application.createDataStore(
        name = PREFERENCE_NAME
    )


    val isBlack = preferencesKey<Boolean>("isBlack")
    //*******************use DataStore

    //*******************MMKV

    private val mmkv by lazy {
        MMKV.defaultMMKV()!!
    }


    val isFirstLogin by mmkv.boolean()

    val numberOfStartUp1 by mmkv.int()

    var model by mmkv.parcelable(
        defaultValue = BackUpModel(
            "11",
            "url",
            null,
            1
        )
    )
//    var backUpList by mmkv?.parcelable<BackUpModel>()

    //*******************MMKV

}